package com.xu.stopThread;

public class SimpleWN {
    final static Object object = new Object();

    public static class T1 implements Runnable{
        @Override
        public void run() {
            synchronized (object){
                System.out.println(System.currentTimeMillis()+":T1 start!");
                try {
                    System.out.println(System.currentTimeMillis()+":T1 wait for Objcet");
                    object.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(System.currentTimeMillis()+":T1 end!");
            }
        }
    }

    public static class T2 implements Runnable{

        @Override
        public void run() {
            synchronized (object) {
                System.out.println(System.currentTimeMillis() + ":T2 start! notify one Thread");
                object.notify();
                System.out.println(System.currentTimeMillis() + "T2 end!");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }


    public static void main(String[] args) {
        Thread t1 = new Thread(new T1());
        Thread t2 = new Thread(new T2());
        t1.start();
        t2.start();

    }


}
